package com.parsechina.hpush.broker.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.io.File;

import static com.parsechina.hpush.broker.config.MqttConstants.DEFAULT_HPUSH_STORE_MAP_DB_FILENAME;


/**
 * 推送配置
 *
 * @author linfeng
 * @date 2019-07-21
 **/
@Configuration
@ConfigurationProperties(prefix = "hpush")
public class HPushConfig {

    /**
     * host
     */
    private String host = "0.0.0.0";
    /**
     * 推送端口
     */
    private Integer port = 1883;
    /**
     * websocket 端口
     */
    private Integer websocketPort = 8083;
    /**
     * 允许匿名访问
     */
    private Boolean allowAnonymous = true;
    /**
     * 允许0字节客户端ID
     */
    private Boolean allowZeroByteClientId = false;
    /**
     * 允许匿名客户端
     */
    private Boolean allowAnonymousClient = true;
    /**
     * 自动保存时间间隔
     */
    private Integer autoSaveInterval = 30;
    /**
     * 内存存储
     */
    private Boolean persistentMemory = false;

    /**
     * 数据库存储地址
     */
    private String persistentStorePath = System.getProperty("user.dir") + File.separator + DEFAULT_HPUSH_STORE_MAP_DB_FILENAME;

    private ClusterConfig cluster;

    private UniqueIdProperties unique;

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Integer getWebsocketPort() {
        return websocketPort;
    }

    public void setWebsocketPort(Integer websocketPort) {
        this.websocketPort = websocketPort;
    }

    public Boolean getAllowAnonymous() {
        return allowAnonymous;
    }

    public void setAllowAnonymous(Boolean allowAnonymous) {
        this.allowAnonymous = allowAnonymous;
    }

    public Boolean getAllowZeroByteClientId() {
        return allowZeroByteClientId;
    }

    public void setAllowZeroByteClientId(Boolean allowZeroByteClientId) {
        this.allowZeroByteClientId = allowZeroByteClientId;
    }

    public Boolean getAllowAnonymousClient() {
        return allowAnonymousClient;
    }

    public void setAllowAnonymousClient(Boolean allowAnonymousClient) {
        this.allowAnonymousClient = allowAnonymousClient;
    }

    public Integer getAutoSaveInterval() {
        return autoSaveInterval;
    }

    public void setAutoSaveInterval(Integer autoSaveInterval) {
        this.autoSaveInterval = autoSaveInterval;
    }

    public Boolean getPersistentMemory() {
        return persistentMemory;
    }

    public void setPersistentMemory(Boolean persistentMemory) {
        this.persistentMemory = persistentMemory;
    }

    public String getPersistentStorePath() {
        return persistentStorePath;
    }

    public void setPersistentStorePath(String persistentStorePath) {
        this.persistentStorePath = persistentStorePath;
    }

    public ClusterConfig getCluster() {
        return cluster;
    }

    public void setCluster(ClusterConfig cluster) {
        this.cluster = cluster;
    }

    public UniqueIdProperties getUnique() {
        return unique;
    }

    public void setUnique(UniqueIdProperties unique) {
        this.unique = unique;
    }

    public static class ClusterConfig {

        private String instanceId;
        private String redisAddress = "redis://127.0.0.1:6379";
        private Integer redisTimeout = 3000;

        public String getInstanceId() {
            return instanceId;
        }

        public void setInstanceId(String instanceId) {
            this.instanceId = instanceId;
        }

        public String getRedisAddress() {
            return redisAddress;
        }

        public void setRedisAddress(String redisAddress) {
            this.redisAddress = redisAddress;
        }

        public Integer getRedisTimeout() {
            return redisTimeout;
        }

        public void setRedisTimeout(Integer redisTimeout) {
            this.redisTimeout = redisTimeout;
        }
    }
    

}
